<template>
	<uni-table border stripe>
		<!-- 表格数据行 -->
		<uni-tr>
			<uni-td>状态(开启中)</uni-td>
			<uni-td>
				<view>
					<switch @change="switchChange" :checked="switchV" />
				</view>
			</uni-td>
		</uni-tr>
		<uni-tr>
			<uni-td>
				时间间隔
			</uni-td>
			<uni-td>
				<view>
					<radio-group @change="handleRadioChange">
						<view>
							<label class="radio">
								<radio value="1800" :checked="timeV==1800" />半小时
							</label>
							<label class="radio">
								<radio value="3600" :checked="timeV==3600" />1小时
							</label>
						</view>
						<view>
							<label class="radio">
								<radio value="7200" :checked="timeV==7200" />2小时
							</label>
							<label class="radio">
								<radio value="10800" :checked="timeV==10800" />3小时
							</label>
						</view>
					</radio-group>
				</view>
				<view>
				</view>
			</uni-td>
		</uni-tr>
		<uni-tr>
			<uni-td>
				提示
			</uni-td>
			<uni-td>
				<text style="color: red;">更改设置以后要刷新页面生效</text>
			</uni-td>
		</uni-tr>
		<uni-tr>
			<uni-td><button type="default" :plain="true" @click="doGoBack()">返回</button></uni-td>
			<uni-td><button type="primary" @click="doSet()">确认</button></uni-td>
		</uni-tr>
	</uni-table>

</template>

<script setup>
	import {
		ref,
		onMounted,
		inject
	} from 'vue';
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app";
	onMounted(() => {
		http.post("/personConfig/getPersonPlanUndoNotifyConfig").then((res) => {
			if (res && res.data && res.data.code == 1) {
				timeV.value = res.data.data.time;
				switchV.value = res.data.data.open;
			}
		}).catch((re) => {
			console.log(re);
		});
	})
	onLoad(() => {

	})
	const http = inject("$http");
	const switchV = ref(true);
	const timeV = ref();

	function switchChange() {
		switchV.value = !switchV.value;
	}

	function doGoBack() {
		uni.navigateBack();
	}

	function handleRadioChange(event) {
		console.log(event)
		timeV.value = event.detail.value;
	}

	function doSet() {
		let params = {}
		params.open = switchV.value;
		params.time = timeV.value;
		http.post("/personConfig/editPersonPlanUndoNotifyConfig", params).then((res) => {
			if (res && res.data && res.data.code == 1) {
				uni.showToast({
					title: '设置成功',
					//将值设置为 success 或者直接不用写icon这个参数
					icon: 'success',
					//显示持续时间为 2秒
					duration: 3000
				})
			}
		}).catch((re) => {
			console.log(re);
		});
	}
</script>